﻿using EM.Components.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using EM.Components.Entities;
using System.Collections.Generic;
using System.Linq;


namespace EM.Components.DataAccess.Tests
{
    
    
    /// <summary>
    ///This is a test class for CampaignDataAccessTest and is intended
    ///to contain all CampaignDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CampaignDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetAll
        ///</summary>
        [TestMethod()]
        public void GetAllTest()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            List<EM_Campaigns> expected = null;
            EMEntities da=new EMEntities();
            expected = (from c in da.EM_Campaigns select c).ToList<EM_Campaigns>();
            List<EM_Campaigns> actual;
            actual = target.GetAll();
            Assert.AreEqual(true,(expected.Count==actual.Count()));
        }

        /// <summary>
        ///A test for Get(name)
        ///</summary>
        [TestMethod()]
        public void GetTest()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            string name = string.Empty; // TODO: Initialize to an appropriate value
            name = "wei";
            EM_Campaigns actual;
            actual = target.Get(name);
            Assert.IsNull(actual);
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void AddTest()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            EM_Campaigns entity = new EM_Campaigns(); // TODO: Initialize to an appropriate value
            entity.ApprovedBy = "Wei";
            entity.CampaignID = 0;
            entity.CampaignName = "Playbook";
            entity.CreatedBy = "wei";
            entity.CreatedDate = DateTime.Today;
            entity.Guid = Guid.NewGuid(); 
            entity.Owner = "Wei";
            entity.StartDate = DateTime.Today.AddDays(7);
            entity.Approved = false;
            entity.CampaignDesc = "$145";
            entity.EndDate = DateTime.Today.AddDays(30);
            entity.Submitted = false;
            entity.UpdatedBy = "wei";
            entity.UpdatedDate = DateTime.Today;
            EM_Campaigns actual;
            actual = target.Add(entity);
            Assert.IsNotNull(actual);
        }

        /// <summary>
        ///A test for Get(name)
        ///</summary>
        [TestMethod()]
        public void GetTest1()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            string name = string.Empty; // TODO: Initialize to an appropriate value
            name = "PlayBook";
            EM_Campaigns actual;
            actual = target.Get(name);
            Assert.IsNotNull(actual);
        }

        /// <summary>
        ///A test for Get(id)
        ///</summary>
        [TestMethod()]
        public void GetTest2()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            int entityId = 1; // TODO: Initialize to an appropriate value
            EM_Campaigns actual;
            actual = target.Get(entityId);
            Assert.IsNotNull(actual);
        }

        /// <summary>
        ///A test for Update
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            EM_Campaigns entity = target.Get(2); // TODO: Initialize to an appropriate value
            entity.CampaignDesc = "Buy a cheap playbook";
            EM_Campaigns actual = target.Update(entity);
            Assert.AreEqual(entity.CampaignDesc, actual.CampaignDesc);
        }

        ///// <summary>
        /////NO need
        /////</summary>
        //[TestMethod()]
        //public void CreateCampaignInstancesTest()
        //{
        //    EMEntities pp = new EMEntities();
        //    CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
        //    int emailInstanceID = 0; // TODO: Initialize to an appropriate value
        //    target.CreateCampaignInstances(emailInstanceID);
        //    var cc=from c in pp.EM_EmailInstances
        //          where c.EmailInstanceID==emailInstanceID
        //          select c;
        //    Assert.IsNotNull(cc);
        //}

        /// <summary>
        ///A test for Delete
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(System.ArgumentNullException))]
        public void DeleteTest()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            int entityId = 0; // TODO: Initialize to an appropriate value
            target.Delete(entityId);
        }

        /// <summary>
        ///A test for Delete
        ///</summary>
        [TestMethod()]
        public void DeleteTest1()
        {
            CampaignDataAccess target = new CampaignDataAccess(); // TODO: Initialize to an appropriate value
            int entityId = 1; // TODO: Initialize to an appropriate value
            target.Delete(entityId);
            Assert.IsNull(target.Get(1));
        }
    }
}
